package com.bkhech.home.practice.javacore.collection.iterator;

import java.util.ArrayList;
import java.util.List;

/**
 * 使用 removeIf() 替换 iterator.remove() 方式
 * 点开源码，可以看到其实底层也是用了Iterator的remove()方法
 *
 * @author guowm
 * @date 2022/12/1
 */
public class ReplaceIteRemoveWithRemoveIfTest {
    public static void main(String[] args) {
        testReplaceIteratorRemoveWithRemoveIf();
    }

    public static void testReplaceIteratorRemoveWithRemoveIf() {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("one");
        list.add("two");
        list.add("three");

        System.out.println("list,before:" + list);
        list.removeIf("one"::equals);
        System.out.println("list,after:" + list);
    }
}
